package com.agsmobi.digitapp;

import java.util.ArrayList;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;

public class HorizontalScrollNumberTilesActivity extends BaseActivity implements OnClickListener{

	
	private int numberOfDisplay;
	private int positionX;
	private int positionY;
	private int width;
	private int length;
	private ArrayList<Integer> numbers;
	
	private HorizontalScrollView horizontalScrollView;
	private LinearLayout liItems;
	private ArrayList<Button> btnDigits;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_horizontalscrollnumbertiles);
		loadControl();
		loadData();
		show();
	}

	@Override
	protected void loadControl() {
		// TODO Auto-generated method stub
		super.loadControl();
		horizontalScrollView = (HorizontalScrollView)findViewById(R.id.horizontalScrollView);
		liItems = (LinearLayout)findViewById(R.id.liItems);
	}

	@Override
	protected void loadData() {
		// TODO Auto-generated method stub
		super.loadData();
		
		numberOfDisplay = 4;
		
		positionX = 250;
		positionY = 100;
		
		width = 300;
		length = 100;
		
		numbers = new ArrayList<Integer>();
		numbers.add(1);
		numbers.add(2);
		numbers.add(12);
		numbers.add(2);
		numbers.add(2);
		numbers.add(12);
		
	}

	private void show(){
		LayoutParams paramsHori = 
				new LayoutParams(width,length);
		paramsHori.setMargins(positionX,positionY,0,0);
		
		horizontalScrollView.setLayoutParams(paramsHori);
		
		btnDigits = new ArrayList<Button>();
		liItems.removeAllViews();
		int size = width/numberOfDisplay;
		for(int i = 0;i<numbers.size();i++){
			Button btnTemp = new Button(this);
			LayoutParams params = new LayoutParams(size,size);
			btnTemp.setLayoutParams(params);
			btnTemp.setId(i*10);
			//btnTemp.setText(HorizontalScrollNumberData.numbers.get(i).toString());
			btnTemp.setBackgroundResource(imageDigit[numbers.get(i)]);
			liItems.addView(btnTemp);
			btnDigits.add(btnTemp);
			btnTemp.setOnClickListener(this);
		}
	}
	
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		int id = v.getId();
		for(int i = 0;i<btnDigits.size();i++){
			if(id == btnDigits.get(i).getId()){
				String me = String.valueOf(numbers.get(i));
				showMessage(me,true);
			}
		}
	}

}





